﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace TimeSheetControl.ObjectModel
{
    public class TimeSheet : List<TimeSheetEntry>
    {
        public static string Serialize(TimeSheet sheet)
        {
            MemoryStream ms = new MemoryStream();
            XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(TimeSheet));
            x.Serialize(ms, sheet);
            ms.Seek(0, 0);
            StreamReader sr = new StreamReader(ms);
            return sr.ReadToEnd();
        }

        public static TimeSheet Deserialize(string xml)
        {
            try
            {

                XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(TimeSheet));
                StringReader sr = new StringReader(xml);
                TimeSheet ret = x.Deserialize(sr) as TimeSheet;
                return ret;
            }
            catch
            {
                return null;
            }
        }

    }
}
